package cn.org.mrliu.ssm.util;

import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import com.squareup.okhttp.Callback;

public class WebSocketUtil {
	private String api = "http://localhost:8080/spring-websocket/api/send";

	public void send(String sender, String receiver, String message) throws Exception {
		send(sender, receiver, message, null);
	}

	public void send(String sender, String receiver, String message, Callback callback) throws Exception {
		_send(sender, Arrays.asList(receiver), message, callback);
	}

	public void send(String sender, List<String> receivers, String message) throws Exception {
		send(sender, receivers, message, null);
	}

	public void send(String sender, List<String> receivers, String message, Callback callback) throws Exception {
		_send(sender, receivers, message, callback);
	}

	private void _send(String sender, List<String> receivers, String message, Callback callback) throws Exception {
		Map<String, Object> param = new LinkedHashMap<String,Object>();
		param.put("sender", sender);
		param.put("receiver", receivers);
		HttpUtil.get(api,param,callback);
	}
}
